import courseData from '../../../data/course'
import cartData from '../../../data/cart'
import Render from './Render'

export default class Course {
  constructor(oList, observer) {
    this.oList = oList
    this.observer = observer
    this.courseData = courseData
    this.cartData = cartData

    this.init()
  }

  init() {
    this.formatData()
    new Render(this.oList, this.courseData, this.cartData,this.observer)
  }
  /**
   * 数据处理：将 courseData 中在 cartData 中的数据 state 置位 1
   */
  formatData () {
    this.courseData = this.courseData.filter(item => {
      item.state = 0
      this.cartData.forEach(cartItem => {
        if (cartItem.id === item.id) {
          item.state = 1
        }
      })
      return true
    })
  }
}
